<span class='l l-1 source java'><s class='meta import java' data-entity-scope='meta.import.java'><s class='keyword other class-fns java' data-entity-scope='keyword.other.class-fns.java'>import</s> <s class='entity name type import java' data-entity-scope='entity.name.type.import.java'>java.util.Scanner</s>;</s>
</span><span class='l l-2 source java'>
</span><span class='l l-3 source java'><s class='meta definition class java' data-entity-scope='meta.definition.class.java'><s class='storage modifier java' data-entity-scope='storage.modifier.java'>public </s><s class='storage type java' data-entity-scope='storage.type.java'>class</s> <s class='entity name type class java' data-entity-scope='entity.name.type.class.java'>Life</s> </s>{
</span><span class='l l-4 source java'><s class='meta definition method java' data-entity-scope='meta.definition.method.java'>    <s class='storage modifier java' data-entity-scope='storage.modifier.java'>public static </s><s class='storage type java' data-entity-scope='storage.type.java'>void</s> <s class='entity name function java' data-entity-scope='entity.name.function.java'>show</s><s class='meta definition param-list java' data-entity-scope='meta.definition.param-list.java'>(<s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] grid</s>)</s>{
</span><span class='l l-5 source java'>        <s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>String</s> s = <s class='string quoted double java' data-entity-scope='string.quoted.double.java'><s class='punctuation definition string begin java' data-entity-scope='punctuation.definition.string.begin.java'>&quot;</s><s class='punctuation definition string end java' data-entity-scope='punctuation.definition.string.end.java'>&quot;</s></s>;
</span><span class='l l-6 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[] row : grid){
</span><span class='l l-7 source java'>            <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>boolean</s> val : row)
</span><span class='l l-8 source java'>                <s class='keyword control java' data-entity-scope='keyword.control.java'>if</s>(val)
</span><span class='l l-9 source java'>                    s <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>+</s>= <s class='string quoted double java' data-entity-scope='string.quoted.double.java'><s class='punctuation definition string begin java' data-entity-scope='punctuation.definition.string.begin.java'>&quot;</s>*<s class='punctuation definition string end java' data-entity-scope='punctuation.definition.string.end.java'>&quot;</s></s>;
</span><span class='l l-10 source java'>                <s class='keyword control java' data-entity-scope='keyword.control.java'>else</s>
</span><span class='l l-11 source java'>                    s <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>+</s>= <s class='string quoted double java' data-entity-scope='string.quoted.double.java'><s class='punctuation definition string begin java' data-entity-scope='punctuation.definition.string.begin.java'>&quot;</s>.<s class='punctuation definition string end java' data-entity-scope='punctuation.definition.string.end.java'>&quot;</s></s>;
</span><span class='l l-12 source java'>            s <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>+</s>= <s class='string quoted double java' data-entity-scope='string.quoted.double.java'><s class='punctuation definition string begin java' data-entity-scope='punctuation.definition.string.begin.java'>&quot;</s><s class='constant character escape java' data-entity-scope='constant.character.escape.java'>\n</s><s class='punctuation definition string end java' data-entity-scope='punctuation.definition.string.end.java'>&quot;</s></s>;
</span><span class='l l-13 source java'>        }
</span><span class='l l-14 source java'>        <s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>System</s>.out.println(s);
</span><span class='l l-15 source java'>    }
</span><span class='l l-16 source java'>
</span><span class='l l-17 source java'>    <s class='storage modifier access-control java' data-entity-scope='storage.modifier.access-control.java'>public</s> <s class='storage modifier java' data-entity-scope='storage.modifier.java'>static</s> <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] gen(){
</span><span class='l l-18 source java'>        <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] grid = <s class='keyword other class-fns java' data-entity-scope='keyword.other.class-fns.java'>new</s> <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[<s class='constant numeric java' data-entity-scope='constant.numeric.java'>10</s>][<s class='constant numeric java' data-entity-scope='constant.numeric.java'>10</s>];
</span><span class='l l-19 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>int</s> r = <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>; r <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>10</s>; r<s class='keyword operator increment-decrement java' data-entity-scope='keyword.operator.increment-decrement.java'>++</s>)
</span><span class='l l-20 source java'>            <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>int</s> c = <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>; c <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>10</s>; c<s class='keyword operator increment-decrement java' data-entity-scope='keyword.operator.increment-decrement.java'>++</s>)
</span><span class='l l-21 source java'>                <s class='keyword control java' data-entity-scope='keyword.control.java'>if</s>( <s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>Math</s>.random() <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&gt;</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0.7</s> )
</span><span class='l l-22 source java'>                    grid[r][c] = <s class='constant language java' data-entity-scope='constant.language.java'>true</s>;
</span><span class='l l-23 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>return</s> grid;
</span><span class='l l-24 source java'>    }
</span><span class='l l-25 source java'>
</span><span class='l l-26 source java'><s class='meta definition method java' data-entity-scope='meta.definition.method.java'>    <s class='storage modifier java' data-entity-scope='storage.modifier.java'>public static </s><s class='storage type java' data-entity-scope='storage.type.java'>void</s> <s class='entity name function java' data-entity-scope='entity.name.function.java'>main</s><s class='meta definition param-list java' data-entity-scope='meta.definition.param-list.java'>(<s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>String</s>[] args</s>)</s>{
</span><span class='l l-27 source java'>        <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] world = gen();
</span><span class='l l-28 source java'>        show(world);
</span><span class='l l-29 source java'>        <s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>System</s>.out.println();
</span><span class='l l-30 source java'>        world = nextGen(world);
</span><span class='l l-31 source java'>        show(world);
</span><span class='l l-32 source java'>        <s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>Scanner</s> s = <s class='keyword other class-fns java' data-entity-scope='keyword.other.class-fns.java'>new</s> <s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>Scanner</s>(<s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>System</s>.in);
</span><span class='l l-33 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>while</s>(s.nextLine().length() <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>==</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>){
</span><span class='l l-34 source java'>            <s class='support type built-ins java' data-entity-scope='support.type.built-ins.java'>System</s>.out.println();
</span><span class='l l-35 source java'>            world = nextGen(world);
</span><span class='l l-36 source java'>            show(world);
</span><span class='l l-37 source java'>
</span><span class='l l-38 source java'>        }
</span><span class='l l-39 source java'>    }
</span><span class='l l-40 source java'>
</span><span class='l l-41 source java'>    <s class='storage modifier access-control java' data-entity-scope='storage.modifier.access-control.java'>public</s> <s class='storage modifier java' data-entity-scope='storage.modifier.java'>static</s> <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] nextGen(<s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] world){
</span><span class='l l-42 source java'>        <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] newWorld
</span><span class='l l-43 source java'>            = <s class='keyword other class-fns java' data-entity-scope='keyword.other.class-fns.java'>new</s> <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[world.length][world[<s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>].length];
</span><span class='l l-44 source java'>        <s class='storage type java' data-entity-scope='storage.type.java'>int</s> num;
</span><span class='l l-45 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>int</s> r = <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>; r <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;</s> world.length; r<s class='keyword operator increment-decrement java' data-entity-scope='keyword.operator.increment-decrement.java'>++</s>){
</span><span class='l l-46 source java'>            <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>int</s> c = <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>; c <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;</s> world[<s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>].length; c<s class='keyword operator increment-decrement java' data-entity-scope='keyword.operator.increment-decrement.java'>++</s>){
</span><span class='l l-47 source java'>                num = numNeighbors(world, r, c);
</span><span class='l l-48 source java'>                <s class='keyword control java' data-entity-scope='keyword.control.java'>if</s>( occupiedNext(num, world[r][c]) )
</span><span class='l l-49 source java'>                    newWorld[r][c] = <s class='constant language java' data-entity-scope='constant.language.java'>true</s>;
</span><span class='l l-50 source java'>            }
</span><span class='l l-51 source java'>        }
</span><span class='l l-52 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>return</s> newWorld;
</span><span class='l l-53 source java'>    }
</span><span class='l l-54 source java'>
</span><span class='l l-55 source java'><s class='meta definition method java' data-entity-scope='meta.definition.method.java'>    <s class='storage modifier java' data-entity-scope='storage.modifier.java'>public static </s><s class='storage type java' data-entity-scope='storage.type.java'>boolean</s> <s class='entity name function java' data-entity-scope='entity.name.function.java'>occupiedNext</s><s class='meta definition param-list java' data-entity-scope='meta.definition.param-list.java'>(<s class='storage type java' data-entity-scope='storage.type.java'>int</s> numNeighbors, <s class='storage type java' data-entity-scope='storage.type.java'>boolean</s> occupied</s>)</s>{
</span><span class='l l-56 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>if</s>( occupied <s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>&amp;&amp;</s> (numNeighbors <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>==</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>2</s> <s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>||</s> numNeighbors <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>==</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>3</s>))
</span><span class='l l-57 source java'>            <s class='keyword control java' data-entity-scope='keyword.control.java'>return</s> <s class='constant language java' data-entity-scope='constant.language.java'>true</s>;
</span><span class='l l-58 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>else</s> <s class='keyword control java' data-entity-scope='keyword.control.java'>if</s> (<s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>!</s>occupied <s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>&amp;&amp;</s> numNeighbors <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>==</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>3</s>)
</span><span class='l l-59 source java'>            <s class='keyword control java' data-entity-scope='keyword.control.java'>return</s> <s class='constant language java' data-entity-scope='constant.language.java'>true</s>;
</span><span class='l l-60 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>else</s>
</span><span class='l l-61 source java'>            <s class='keyword control java' data-entity-scope='keyword.control.java'>return</s> <s class='constant language java' data-entity-scope='constant.language.java'>false</s>;
</span><span class='l l-62 source java'>    }
</span><span class='l l-63 source java'>
</span><span class='l l-64 source java'><s class='meta definition method java' data-entity-scope='meta.definition.method.java'>    <s class='storage modifier java' data-entity-scope='storage.modifier.java'>private static </s><s class='storage type java' data-entity-scope='storage.type.java'>int</s> <s class='entity name function java' data-entity-scope='entity.name.function.java'>numNeighbors</s><s class='meta definition param-list java' data-entity-scope='meta.definition.param-list.java'>(<s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] world, <s class='storage type java' data-entity-scope='storage.type.java'>int</s> row, <s class='storage type java' data-entity-scope='storage.type.java'>int</s> col</s>) </s>{
</span><span class='l l-65 source java'>        <s class='storage type java' data-entity-scope='storage.type.java'>int</s> num = world[row][col] ? <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>-</s><s class='constant numeric java' data-entity-scope='constant.numeric.java'>1</s> : <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>;
</span><span class='l l-66 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>int</s> r = row <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>-</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>1</s>; r <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;=</s> row <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>+</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>1</s>; r<s class='keyword operator increment-decrement java' data-entity-scope='keyword.operator.increment-decrement.java'>++</s>)
</span><span class='l l-67 source java'>            <s class='keyword control java' data-entity-scope='keyword.control.java'>for</s>(<s class='storage type java' data-entity-scope='storage.type.java'>int</s> c = col <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>-</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>1</s>; c <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;=</s> col <s class='keyword operator arithmetic java' data-entity-scope='keyword.operator.arithmetic.java'>+</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>1</s>; c<s class='keyword operator increment-decrement java' data-entity-scope='keyword.operator.increment-decrement.java'>++</s>)
</span><span class='l l-68 source java'>                <s class='keyword control java' data-entity-scope='keyword.control.java'>if</s>( inbounds(world, r, c) <s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>&amp;&amp;</s> world[r][c] )
</span><span class='l l-69 source java'>                    num<s class='keyword operator increment-decrement java' data-entity-scope='keyword.operator.increment-decrement.java'>++</s>;
</span><span class='l l-70 source java'>
</span><span class='l l-71 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>return</s> num;
</span><span class='l l-72 source java'>    }
</span><span class='l l-73 source java'>
</span><span class='l l-74 source java'><s class='meta definition method java' data-entity-scope='meta.definition.method.java'>    <s class='storage modifier java' data-entity-scope='storage.modifier.java'>private static </s><s class='storage type java' data-entity-scope='storage.type.java'>boolean</s> <s class='entity name function java' data-entity-scope='entity.name.function.java'>inbounds</s><s class='meta definition param-list java' data-entity-scope='meta.definition.param-list.java'>(<s class='storage type java' data-entity-scope='storage.type.java'>boolean</s>[][] world, <s class='storage type java' data-entity-scope='storage.type.java'>int</s> r, <s class='storage type java' data-entity-scope='storage.type.java'>int</s> c</s>) </s>{
</span><span class='l l-75 source java'>        <s class='keyword control java' data-entity-scope='keyword.control.java'>return</s> r <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&gt;=</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s> <s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>&amp;&amp;</s> r <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;</s> world.length <s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>&amp;&amp;</s> c <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&gt;=</s> <s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s> <s class='keyword operator logical java' data-entity-scope='keyword.operator.logical.java'>&amp;&amp;</s>
</span><span class='l l-76 source java'>        c <s class='keyword operator comparison java' data-entity-scope='keyword.operator.comparison.java'>&lt;</s> world[<s class='constant numeric java' data-entity-scope='constant.numeric.java'>0</s>].length;
</span><span class='l l-77 source java'>    }
</span><span class='l l-78 source java'>
</span><span class='l l-79 source java'>
</span><span class='l l-80 source java'>
</span><span class='l l-81 source java'>}
</span>
